package cn.guo.jmw.handlers;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by guo on 2015/10/19.
 */
public class LogHandler implements InvocationHandler {

    Object obj;

    public LogHandler(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.doBefore(args);
        Object o = method.invoke(obj,args);
        this.doAfter();
        return o;
    }

    private void doAfter() {
        System.out.println("Do After Method Invoked.");

    }

    private void doBefore(Object[] args) {
        System.out.println("Do Before Method Invoked. ");
    }
}
